package it.blueocean.acanto.platform.dao.impl;

import it.blueocean.acanto.entities.platform.MenuItem;
import it.blueocean.acanto.platform.dao.NavigationDao;

import java.util.List;

import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;

@Named("navigationDao")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class NavigationDaoImpl implements NavigationDao
{
	private final static Logger logger = LoggerFactory.getLogger(NavigationDaoImpl.class);
	
	@PersistenceContext(type = PersistenceContextType.EXTENDED)
	private EntityManager entityManager;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<MenuItem> loadMenuItems()
	{
		List<MenuItem> result = entityManager.createQuery("from MenuItem m order by m.id, m.parent, m.position").getResultList();
		
		logger.debug("Retrived MenuItem list" + result);
		
		return result;
	}

}
